﻿// cmdAddBrepBoxCommand.cpp
//

#include "stdafx.h"


////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// BEGIN AddBrepBoxCommand command
//

#pragma region AddBrepBoxCommand command

class CCommandAddBrepBoxCommand : public CRhinoCommand
{
public:
	CCommandAddBrepBoxCommand() = default;
	UUID CommandUUID() override
	{
		// {4a54e669-d89a-46c0-902f-0f0a359c7d1c}
		static const GUID AddBrepBoxCommandCommand_UUID =
		{0x4a54e669,0xd89a,0x46c0,{0x90,0x2f,0x0f,0x0a,0x35,0x9c,0x7d,0x1c}};
		return AddBrepBoxCommandCommand_UUID;
	}
	const wchar_t* EnglishCommandName() override { return L"AddBrepBox"; }
	CRhinoCommand::result RunCommand(const CRhinoCommandContext& context) override;
};

// The one and only CCommandAddBrepBoxCommand object
static class CCommandAddBrepBoxCommand theAddBrepBoxCommandCommand;

CRhinoCommand::result CCommandAddBrepBoxCommand::RunCommand(const CRhinoCommandContext& context)
{
    CRhinoCommand::result rc = CRhinoCommand::nothing;

    // define the corners of the box
    ON_3dPointArray corners;
    corners.Append(ON_3dPoint(0.0, 0.0, 0.0));
    corners.Append(ON_3dPoint(10.0, 0.0, 0.0));
    corners.Append(ON_3dPoint(10.0, 10.0, 0.0));
    corners.Append(ON_3dPoint(0.0, 10.0, 0.0));
    corners.Append(ON_3dPoint(0.0, 0.0, 10.0));
    corners.Append(ON_3dPoint(10.0, 0.0, 10.0));
    corners.Append(ON_3dPoint(10.0, 10.0, 10.0));
    corners.Append(ON_3dPoint(0.0, 10.0, 10.0));

    // Build the brep  
    ON_Brep* pBrep = ON_BrepBox(corners);
    if (pBrep)
    {
        CRhinoBrepObject* pObject = new CRhinoBrepObject();
        pObject->SetBrep(pBrep);
        if (context.m_doc.AddObject(pObject))
        {
            context.m_doc.Redraw();
            rc = CRhinoCommand::success;
        }
        else
        {
            delete pObject;
            pObject = 0;
            rc = CRhinoCommand::failure;
        }
    }
    return rc;
}

#pragma endregion

//
// END AddBrepBoxCommand command
//
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
